<template>
  <div class="commonQuery" style="width: 100% ; height: 100%">
    <el-row>
      <el-col :span="24">
        <avue-form
          ref="partQuery"
          class="partQueryClass"
          v-model="avueData"
          :option="options"
        >
          <template slot-scope="{  }" slot="menuForm">
            <div class="btn flex alignCenter">
              <el-button
                :size="btnSize"
                type="primary"
                plain
                @click="queryList"
              >查询
              </el-button
              >
              <el-button
                :size="btnSize"
                class="clearButton"
                size="mini"
                plain
                @click="clearFrom"
              >清空
              </el-button
              >
            </div>
          </template>
        </avue-form>
      </el-col>
    </el-row>
    <el-divider v-if="splitLine"></el-divider>
  </div>
</template>
<script>
import BaseComp from "./baseComp";

export default {
  name: 'commonQuery',
  extends: BaseComp,
  props: {
    menuSpan: {
      type: [Number, String],
      default: 2
    },
    queryOption: {
      type: Object,
      default: () => {
      }
    },
    queryData: {
      type: Object,
      default: () => {
      }
    },
    splitLine: {
      type: Boolean,
      default: true
    },
    btnSize: {
      type: String,
      default: "mini"
    }
  },
  watch: {
    queryOption: {
      deep: true,
      handler(newVal) {
        this.initOptions(newVal);
      },
    },
    queryData: {
      deep: true,
      handler(newVal) {
        this.initAvueData(newVal);
      },
    },
  },
  data() {
    return {
      avueData: {},
      options: {},
    };
  },
  created() {
    this.initOptions(this.queryOption);
    this.initAvueData(this.queryData);
  },
  methods: {
    /**
     * 初始化options对象
     */
    initOptions(newVal) {
      this.options = this.deepClone(newVal);
      this.options.column.forEach(item => {
        item.label = '';
      })
      this.options.submitBtn = false;
      this.options.emptyBtn = false,
        this.options.arrow = false;
      this.options.menuPosition = 'center';
      this.options.menuSpan = Number(this.menuSpan);
      this.options.menuPosition = "left";
    },
    /**
     * 初始化avue数值对象
     */
    initAvueData(newVal) {
      if (newVal) {
        delete newVal.path;
        this.avueData = JSON.parse(JSON.stringify(newVal));
      }
    },
    // 条件查询，这里需要把条件传给父组件
    queryList() {
      // 把当前页恢复为1
      this.$emit("pageClearEvent", true);
      this.$emit("queryData", this.avueData);
      this.$emit("queryList", this.avueData);
    },
    clearFrom() {
      this.$refs.partQuery.resetForm();
      this.$nextTick(() => {
        this.queryList();
      })
    },
  },
};
</script>
<style lang="less" scoped>
.commonQuery {
  .el-row {
    padding: 15px 0px;
  }

  .partQueryClass {
    /deep/ .avue-group {
      .el-form-item {
        margin-bottom: 0px;
      }

      /** 
      .el-button--primary {
        background: var(--theme_color);
        color: #fff;
      }

      .clearButton {
        margin-left: 6px;
        color: #71798B;
      }

      .el-button--small {
        border-radius: 2px;
      }
        */
    }

  }

  .query {
    width: 100%;

    & > div {
      font-size: 16px;
      min-width: 80px;
    }

    .btns {
      font-size: 14px;
      // padding-right: 44px;
    }
  }

  .shu {
    border-right: solid var(--theme_color) 4px;
    height: 16px;
    margin-top: 4%;
    margin-right: 3%;
  }

  .el-form {
    margin-top: 16px;
  }

  .el-form-item--mini.el-form-item,
  .el-form-item--small.el-form-item {
    margin-bottom: 16px;
  }

  .el-form--inline .el-form-item {
    margin-right: 16px;
  }

  /deep/ .el-collapse-item__header {
    display: none !important;
  }

  /deep/ .el-collapse {
    border-top: none;
  }

  /deep/ .el-collapse-item__wrap {
    border-bottom: none;
  }

  .btn {
    margin-left: 24px;
  }

  .line {
    width: 100%;
    height: 1px;
    background: #ebeef1;
    margin: 12px auto 0px;
  }

  //三角箭头
  /deep/ .el-icon-arrow-up:before {
    content: "";
    font-size: 15px;
    color: #666666;
  }

  /deep/ .el-icon-arrow-down:before {
    content: "\e790";
    font-size: 15px;
    color: #666666;
  }

  // 分割线
  /deep/ .el-divider--horizontal {
    margin: 5px 0;
  }

  .el-divider {
    background: #EBEEF1;
  }

  /deep/ .el-select {
    width: 100%;
  }
}
</style>

<style lang="less">
.avueTree {
  /deep/ .el-select-dropdown__item {
    height: auto !important;
    background-color: #FFFFFF;
  }

  /deep/ .avue-input-tree__filter {
    padding: 0 20px;
  }
}

</style>
